import type { RouteRecordRaw } from 'vue-router'

// 判断是否有权限
export const hasPermission = (
  permissions: string[],
  route: RouteRecordRaw,
): boolean => {
  // 如果没有permissions，说明不需要权限
  if (!route.meta?.permissions) {
    return true
  }
  // 单个权限
  if (route.meta.permissions.length === 1) {
    return permissions.includes(route.meta.permissions[0])
  }
  // 多个权限
  return route.meta.permissions.some(permission =>
    permissions.includes(permission),
  )
}
